//compositionAPI插件
import VueCompositionAPI from '@vue/composition-api';
//axios请求插件
import axios from 'axios';
//转换编译js代码
import "babel-polyfill";
//echarts数据可视化插件
import echarts from 'echarts';
import ElementUI from 'element-ui';
//element-ui组件库 - 组件的默认尺寸为小
import 'element-ui/lib/theme-chalk/index.css';
// * 这里的自适应需要自行修改依赖文件以到达自适应效果 node_modules -> lib-flexible -> flexible.js 将 refreshRem的函数里的 width = 540 * dpr 改为 width = width * dpr 即可;
import "lib-flexible";
import "lib-flexible/flexible";
//顶部页面加载条
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
//qs - axios参数序列化插件
import qs from 'qs';
import Vue from 'vue';
//重置样式和字体
import '../static/css/main.css';
import '../static/font/font.css';
import App from './App';
//全局封装方法
import base from "./base";
//api原型全局挂载 - 线上接口地址 
import apiUrl from './components/common/Global.vue';
//路由
import router from './router';



//启动项目生产消息
Vue.config.productionTip = false;

Vue.use(ElementUI, { size: 'small' });

Vue.prototype.$echarts = echarts;

NProgress.configure({
    easing: 'ease',
    speed: 500,
    showSpinner: false,
    trickleSpeed: 200,
    minimum: 0.3
})

axios.defaults.withCredentials = true;
Vue.prototype.$axios = axios;

Vue.prototype.qs = qs;


Vue.use(VueCompositionAPI);

Vue.use(base);

Vue.prototype.apiUrl = apiUrl.apiUrl;
Vue.prototype.loginUrl = apiUrl.loginUrl;


//路由监听
router.beforeEach((to, from, next) => {
    NProgress.start();
    let isLogin = window.localStorage.getItem('nameUser')
    if(isLogin){
        next()
      }else{
        if(to.path === "/"){
          next()
        }else {
          alert("没有访问权限或登陆已过期，请重新登陆")
          next('/')
        }
      }
});
//路由跳转结束
router.afterEach(() => {
    NProgress.done()
})
//挂载
new Vue({
    el: '#app',
    router,
    components: {
        App
    },
    template: '<App/>'
})